package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 别名
 */
public class JDBCDemo6 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()) {
            /*
                查看1年级1班一共多少人?
                SELECT COUNT(*) count
                FROM student s
                JOIN class c ON s.class_id=c.id
                WHERE c.name='1年级1班'
             */
            String sql = "SELECT COUNT(*) count " +
                         "FROM student s " +
                         "JOIN class c ON s.class_id=c.id " +
                         "WHERE c.name='1年级1班'";
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                int count = rs.getInt("count");//获取该字段时使用字段别名
                System.out.println("1年级1班总人数:"+count);
            }


        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}


